class_name BuffSakuraAttack
extends BaseBuff

var attack: float = 0
var critical_rate: float = 0
var critical_bonus: float = 0
var knockback: float = 0


func start_buff():
	var particle = (ResourceManager.get_resource("particle_attack_sakura") as PackedScene).instantiate() as GPUParticles2D
	holder.level.bullets_parent.add_child(particle)
	particle.global_position = holder.ray_cast_point.global_position
	
	await get_tree().create_timer(0.3).timeout
	holder.take_hit(get_hit_data(), sender)
	holder.level.camera.start_shake(5.0, 0.3)
	await get_tree().create_timer(2.0).timeout
	queue_free()
	

func get_hit_data():
	var is_critical = randf() <= critical_rate
	var critical_attack = attack * (1.0 + critical_bonus)
	
	var hit_data = HitData.new()
	hit_data.is_critical = is_critical
	hit_data.attack = critical_attack if is_critical else attack
	hit_data.knockback = knockback
	
	return hit_data
	
	
